/*
 * ItemFilterComponentDefinition.java
 *
 * Created on September 2, 2006, 4:15 PM
 *
 * (C) 2006 R. Alexander Milowski
 */

package org.infoset.component;

import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.infoset.xml.Name;
import org.infoset.xml.XMLException;
import org.infoset.xml.filter.ItemFilter;

/**
 *
 * @author alex
 */
public class ItemFilterComponentDefinition extends ComponentDefinitionBase {
   
   static Name DOCUMENT_INPUT_PORT = Name.create("source");
   static Name RESULT_OUTPUT_PORT = Name.create("result");
   static List<Name> inputs = new ArrayList<Name>();
   static List<Name> outputs = new ArrayList<Name>();
   static {
      inputs.add(DOCUMENT_INPUT_PORT);
      outputs.add(RESULT_OUTPUT_PORT);
   }
   Class filterClass;
   
   /** Creates a new instance of ItemFilterComponentDefinition */
   public ItemFilterComponentDefinition(Name name,String vendor,String version,URI vendorLocation,Class filterClass) {
      super(name,vendor,version,vendorLocation);
      this.filterClass = filterClass;
   }

   public Component newInstance() 
      throws XMLException
   {
      try {
         ItemFilter filter = (ItemFilter)filterClass.newInstance();
         return new ItemFilterComponent(name,vendor,version,filter);
      } catch (IllegalAccessException ex) {
         throw new XMLException("Cannot instantiate filter instance.",ex);
      } catch (InstantiationException ex) {
         throw new XMLException("Cannot instantiate filter instance.",ex);
      }
   }
   
   public Collection<Name> getInputs() {
      return inputs;
   }
   
   public Collection<Name> getOutputs() {
      return outputs;
   }
   
}
